package cn.g31010.sip.model
{
	import cn.g31010.sip.view.VideoPanel;
	
	import com.adobe.cairngorm.model.ModelLocator;
	
	import flash.media.*;
	
	import mx.collections.ArrayCollection;
	
	public class VideoModel implements ModelLocator
	{
		private static var modelLocator : VideoModel;
		[Bindable]
		public var videos:ArrayCollection=new ArrayCollection();
		
		public var app:webchat;
		[Bindable]
		public var cams:Array;
		[Bindable]
		public var mics:Array;
		[Bindable]
		public var currentCam:Camera=Camera.getCamera();
		
		public var mycampanel:VideoPanel;
		public static function getInstance() : VideoModel 
		{
			if ( modelLocator == null ){
				modelLocator = new VideoModel();
			}
			return modelLocator;
	   }
	   
   		public function VideoModel() 
   		{
   			if ( VideoModel.modelLocator != null )
				throw new Error( "Only one ModelLocator instance should be instantiated" );	
			cams=Camera.names;
			mics=Microphone.names;
   		}
   		
   		public function addVideoPanel(videoPanel:VideoPanel):void{
   			videos.addItem(videoPanel);
   		}
   		
   		public function hasVideoPanel(name:String):Boolean{
   			for(var i:int=0;i<videos.length;i++){
   				var v:VideoPanel=videos[i] as VideoPanel;
   				if(v.name==name){
   					return true;
   				}
   			}
   			return false;
   		}
   		
   		public function removeVideoPanel(name:String):VideoPanel{
   			for(var i:int=0;i<videos.length;i++){
   				var v:VideoPanel=videos[i] as VideoPanel;
   				if(v.name==name){
   					videos.removeItemAt(i);
   					return v;
   				}
   			}
   			return null;
   		}
	}
}